package com.hntest.service.impl;

import com.hntest.dao.UserFileDao;
import com.hntest.entity.Pager;
import com.hntest.entity.RealAuth;
import com.hntest.entity.UserFile;
import com.hntest.service.UserFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userFileService")
public class UserFileServiceImpl implements UserFileService {
    @Autowired
    private UserFileDao userFileDao;

    public void setUserFileDao(UserFileDao userFileDao) {
        this.userFileDao = userFileDao;
    }

    @Override
    public List<UserFile> getListByPage(Pager pager, UserFile userFile, String time1, String time2) {
        if (time1!=null && time1.equals("")){
            time1=null;
        }
        if (time2!=null && time2.equals("")){
            time2=null;
        }

        //将值存入map中
        Map<String, Object> map = new HashMap<>();
        map.put("userFile",userFile);
        map.put("pageStart", 1);
        map.put("pageEnd", 10000);
        map.put("time1",time1);
        map.put("time2",time2);
        //查询总数量
        pager.setTotalCounts(userFileDao.getListByPage(map).size());

        map.put("pageStart", (pager.getCurrPage() - 1) * pager.getPageSize() + 1);
        map.put("pageEnd", pager.getCurrPage() * pager.getPageSize());

        //将map中带回的数据保存到list集合中返回
        List<UserFile> list = userFileDao.getListByPage(map);
        return list;
    }

    @Override
    public UserFile getUserFileById(int uid) {
        return userFileDao.getUserFileById(uid);
    }

    @Override
    public int update(UserFile userFile) {
        return userFileDao.update(userFile);
    }
}
